home *** CD-ROM | disk | FTP | other *** search
- #include "kant main window.h"
- #include "kant text twiddling.h"
- #include "kant parser.h"
- //#include "kant search.h"
- #include "buttons.h"
- #include "environment.h"
- #include "menus.h"
- #include "popup.h"
- #include "util.h"
- #include "main.h"
- #include "program globals.h"
-
- /* internal procedures for kant main window.c only */
- static void SetupTheMainWindow(WindowDataHandle theData);
- static void ShutDownTheMainWindow(WindowDataHandle theData);
- static void InitializeTheMainWindow(WindowDataHandle theData);
- static void OpenTheMainWindow(WindowDataHandle theData);
- static void IdleInMainWindow(WindowDataHandle theData);
- static void KeyPressedInMainWindow(WindowDataHandle theData, unsigned char theChar);
- static void MouseClickedInMainWindow(WindowDataHandle theData, Point thePoint);
- static void DisposeTheMainWindow(WindowDataHandle theData);
- static void ActivateTheMainWindow(WindowDataHandle theData);
- static void DeactivateTheMainWindow(WindowDataHandle theData);
- static void CopybitsTheMainWindow(WindowDataHandle theData);
- static void DrawTheMainWindow(WindowDataHandle theData, short theDepth);
- static void PutDataIntoTEFields(WindowDataHandle theData);
- static void ResizeControlsInMainWindow(WindowDataHandle theData);
- static void UpdateTheUpdateRgn(WindowDataHandle theData);
-
- enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
- enum { key_PageUp=0x0b, key_PageDown };
- enum { key_Home=0x01 };
- enum { key_End=0x04 };
-
- #define HEADER_SPACE -1
- #define FOOTER_SPACE 5
- #define DEAD_SPACE_LEFT 5
- #define DEAD_SPACE_RIGHT DEAD_SPACE_LEFT
- #define WINDOW_WIDTH 500
- #define WINDOW_HEIGHT 292
- #define kGrowBoxSize 15
-
- enum
- {
- kMainWindowTE=0
- };
-
- #define NUM_TE 1 /* number of editable boxes */
-
- static short gOldForegroundTime; /* stored foreground wait time */
- static short gWhichTE; /* which edit box we're in now */
- static Rect gDestRect[NUM_TE], gViewRect[NUM_TE];
- ControlHandle gVScrollBar, gHScrollBar;
- static Rect gVScrollBarRect, gHScrollBarRect;
- static short gRawBottom;
- static CursHandle gMyIBeamHandle;
- static Boolean gIsActive;
-
- short MainWindowDispatch(WindowDataHandle theData, short theMessage,
- unsigned long misc)
- {
- short theDepth;
- unsigned char theChar;
- Point thePoint;
-
- switch (theMessage)
- {
- case kNull:
- IdleInMainWindow(theData);
- return kSuccess;
- break;
- case kUpdate:
- theDepth=misc&0x7fff;
- DrawTheMainWindow(theData, theDepth);
- return kSuccess;
- break;
- case kOpen:
- OpenTheMainWindow(theData);
- return kSuccess;
- break;
- case kKeydown:
- theChar=misc&charCodeMask;
- KeyPressedInMainWindow(theData, theChar);
- return kSuccess;
- break;
- case kMousedown:
- thePoint.h=(misc>>16)&0x7fff;
- thePoint.v=misc&0x7fff;
- MouseClickedInMainWindow(theData, thePoint);
- return kSuccess;
- break;
- case kActivate:
- ActivateTheMainWindow(theData);
- return kSuccess;
- break;
- case kDeactivate:
- DeactivateTheMainWindow(theData);
- return kSuccess;
- break;
- case kGrow:
- case kZoom:
- ResizeControlsInMainWindow(theData);
- return kFailure; /* still want to do the default processing -- see main.c */
- break;
- case kGetGrowSize:
- SetRect((Rect*)misc, 200, 48+kGrowBoxSize+1, 32766, 32767);
- return kSuccess;
- break;
- case kInitialize:
- InitializeTheMainWindow(theData);
- return kSuccess;
- break;
- case kStartup:
- SetupTheMainWindow(theData);
- return kSuccess;
- break;
- case kDispose:
- DisposeTheMainWindow(theData);
- return kSuccess;
- break;
- case kShutdown:
- ShutDownTheMainWindow(theData);
- return kSuccess;
- break;
- case kCut:
- case kCopy:
- case kPaste:
- case kClear:
- case kSelectAll:
- DealWithEditMenu(theData, theMessage);
- return kSuccess;
- break;
- case kCopybits:
- CopybitsTheMainWindow(theData);
- return kSuccess;
- break;
- }
-
- return kFailure;
- }
-
- void SetupTheMainWindow(WindowDataHandle theData)
- {
- unsigned char *titleStr="\puntitled";
-
- (**theData).windowHeight=qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28;
- (**theData).windowWidth=qd.screenBits.bounds.right-qd.screenBits.bounds.left-70;
- (**theData).windowType=zoomDocProc;
- (**theData).windowBounds.top=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
- (**theData).windowBounds.left=qd.screenBits.bounds.left+10;
- (**theData).hasCloseBox=TRUE;
- (**theData).maxDepth=1;
- Mymemcpy((**theData).windowTitle, titleStr, titleStr[0]+1);
- gRawBottom=(**theData).windowHeight+1-kGrowBoxSize;
- gMyIBeamHandle=GetCursor(iBeamCursor);
- }
-
- void InitializeTheMainWindow(WindowDataHandle theData)
- {
- (**theData).initialTopLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
- (**theData).initialTopLeft.h=qd.screenBits.bounds.left+10;
- }
-
- void ShutDownTheMainWindow(WindowDataHandle theData)
- {
- ReleaseResource((Handle)gMyIBeamHandle);
- }
-
- void OpenTheMainWindow(WindowDataHandle theData)
- {
- TEHandle hTE;
- FontInfo theFontInfo;
-
- SetRect(&gVScrollBarRect, (**theData).windowWidth-kGrowBoxSize, HEADER_SPACE,
- (**theData).windowWidth+1, gRawBottom);
- SetRect(&gHScrollBarRect, -1, (**theData).windowHeight-kGrowBoxSize,
- (**theData).windowWidth-kGrowBoxSize+1, (**theData).windowHeight+1);
- gVScrollBar=NewControl(GetWindowPtr(theData), &gVScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0);
- gHScrollBar=NewControl(GetWindowPtr(theData), &gHScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0);
-
- hTE=GetWindowData_hTE(theData, kMainWindowTE);
- if (hTE==0L)
- {
- GetTERect(GetWindowPtr(theData), &gDestRect[kMainWindowTE]);
- gViewRect[kMainWindowTE]=gDestRect[kMainWindowTE];
- hTE=(**theData).hTE[kMainWindowTE]=TENew(&(gDestRect[kMainWindowTE]), &(gViewRect[kMainWindowTE]));
- TextFont(monaco);
- TextSize(9);
- TextFace(0);
- GetFontInfo(&theFontInfo);
- TextFont(0);
- TextSize(12);
- TextFace(0);
- (**hTE).txFont=monaco;
- (**hTE).txSize=9;
- (**hTE).txFace=0;
- (**hTE).fontAscent=theFontInfo.ascent;
- (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
- AdjustViewRect(hTE);
- gViewRect[kMainWindowTE]=(**hTE).viewRect;
-
- TEAutoView(TRUE, hTE);
- TESetClickLoop((ProcPtr)MyClikLoop, hTE);
-
- gWhichTE=kMainWindowTE;
- PutDataIntoTEFields(theData);
- }
-
- gIsActive=TRUE;
- AdjustVScrollBar(gVScrollBar, hTE);
- (**theData).offscreenNeedsUpdate=TRUE;
- AdjustMenus();
- DrawMenuBar();
- }
-
- void PutDataIntoTEFields(WindowDataHandle theData)
- {
- TEHandle hTE;
-
- hTE=GetWindowData_hTE(theData, kMainWindowTE);
- TESetSelect(0, 0, hTE);
- TEKey(0x00, hTE);
- TEKey(0x08, hTE);
- }
-
- void IdleInMainWindow(WindowDataHandle theData)
- {
- Point thePoint;
-
- if (gInProgress)
- return;
-
- if (gWhichTE==kMainWindowTE)
- TEIdle((**theData).hTE[kMainWindowTE]);
- SetPort(GetWindowPtr(theData));
- GetMouse(&thePoint);
- if (PtInRect(thePoint, &(**GetWindowData_hTE(theData, kMainWindowTE)).viewRect))
- {
- if (!gCustomCursor)
- {
- SetCursor(*gMyIBeamHandle);
- gCustomCursor=TRUE;
- }
- }
- else
- {
- gCustomCursor=FALSE;
- }
- }
-
- void KeyPressedInMainWindow(WindowDataHandle theData, unsigned char theChar)
- {
- TEHandle hTE;
-
- if (gInProgress)
- return;
-
- hTE=GetWindowData_hTE(theData, gWhichTE);
- switch (theChar)
- {
- case key_PageUp:
- RawActionProc(gVScrollBar, inPageUp);
- break;
- case key_PageDown:
- RawActionProc(gVScrollBar, inPageDown);
- break;
- case key_Home:
- TEPinScroll(0, TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- case key_End:
- TEPinScroll(0, -TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- default:
- if (gWhichTE!=kMainWindowTE)
- {
- TEDeactivate((**theData).hTE[gWhichTE]);
- gWhichTE=kMainWindowTE;
- TEActivate((**theData).hTE[gWhichTE]);
- }
- TEKey(theChar, hTE);
- TESelView(hTE);
- AdjustForEndScroll(gVScrollBar, hTE);
- // SetLastFindPosition((**hTE).selEnd);
- break;
- }
-
- AdjustVScrollBar(gVScrollBar, hTE);
- }
-
- void MouseClickedInMainWindow(WindowDataHandle theData, Point thePoint)
- {
- short i;
- Boolean gotone;
- short partCode;
- ControlHandle theControl;
- short scrollDistance;
- short oldSetting;
- ControlActionUPP rawActionUPP=NewControlActionProc(RawActionProc);
- TEHandle hTE;
-
- if (gInProgress)
- return;
-
- gotone=FALSE;
- if (!gotone)
- {
- for (i=0; ((i<NUM_TE) && (!gotone)); i++)
- {
- if (PtInRect(thePoint, &(gDestRect[i])))
- {
- if (i!=gWhichTE)
- {
- TEDeactivate((**theData).hTE[gWhichTE]);
- gWhichTE=i;
- TEActivate((**theData).hTE[gWhichTE]);
- }
-
- if (gWhichTE==kMainWindowTE)
- {
- short oldStart, oldEnd;
-
- hTE=GetWindowData_hTE(theData, kMainWindowTE);
- oldStart=(**hTE).selStart;
- oldEnd=(**hTE).selEnd;
- TEClick(thePoint, (GetTheModifiers()&512) ? TRUE : FALSE, (**theData).hTE[i]);
- // if (((**hTE).selStart!=oldStart) || ((**hTE).selEnd!=oldEnd))
- // SetRefreshOutput(TRUE);
- // SetLastFindPosition((**hTE).selEnd);
- }
-
- gotone=TRUE;
- }
- }
- }
-
- if (!gotone)
- {
- partCode=FindControl(thePoint, GetWindowPtr(theData), &theControl);
- if (theControl==gVScrollBar)
- {
- switch (partCode)
- {
- case inThumb:
- oldSetting=GetControlValue(theControl);
- partCode=TrackControl(theControl, thePoint, 0L);
- if (partCode==inThumb)
- {
- scrollDistance=oldSetting-GetControlValue(theControl);
- if (scrollDistance!=0)
- {
- hTE=GetWindowData_hTE(theData, kMainWindowTE);
- TEPinScroll(0, scrollDistance, hTE);
- }
- }
- gotone=TRUE;
- break;
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- partCode=TrackControl(theControl, thePoint, rawActionUPP);
- gotone=TRUE;
- break;
- }
- }
- }
- }
-
- void DisposeTheMainWindow(WindowDataHandle theData)
- {
- short i;
-
- for (i=0; i<NUM_TE; i++)
- {
- if ((**theData).hTE[i]!=0L)
- TEDispose((**theData).hTE[i]);
- (**theData).hTE[i]=0L;
- }
- }
-
- void ActivateTheMainWindow(WindowDataHandle theData)
- {
- gOldForegroundTime=gForegroundWaitTime;
- gForegroundWaitTime=0;
- TEActivate((**theData).hTE[gWhichTE]);
- gIsActive=TRUE;
- }
-
- void DeactivateTheMainWindow(WindowDataHandle theData)
- {
- gForegroundWaitTime=gOldForegroundTime;
- TEDeactivate((**theData).hTE[gWhichTE]);
- gIsActive=FALSE;
- gCustomCursor=FALSE;
- }
-
- void DrawTheMainWindow(WindowDataHandle theData, short theDepth)
- {
- GrafPtr curPort;
-
- #if 0
- if (theDepth>2)
- {
- GetForeColor(&oldForeColor);
- GetBackColor(&oldBackColor);
- }
- #endif
-
- GetPort(&curPort);
- EraseRect(&(curPort->portRect));
-
- #if 0
- if (theDepth>2)
- {
- RGBForeColor(&oldForeColor);
- RGBBackColor(&oldBackColor);
- }
- #endif
- }
-
- void CopybitsTheMainWindow(WindowDataHandle theData)
- {
- Rect tempRect;
- GrafPtr curPort;
-
- if (gIsActive)
- {
- DrawGrowIcon(GetWindowPtr(theData));
- }
- else
- {
- GetPort(&curPort);
-
- tempRect.bottom=curPort->portRect.bottom;
- tempRect.right=curPort->portRect.right;
- tempRect.left=tempRect.right-kGrowBoxSize+1;
- tempRect.top=tempRect.bottom-kGrowBoxSize+1;
- EraseRect(&tempRect);
- }
-
- UpdateControls(GetWindowPtr(theData), GetWindowPtr(theData)->visRgn);
-
- tempRect=GetWindowPtr(theData)->portRect;
- tempRect.bottom-=kGrowBoxSize;
- tempRect.right-=kGrowBoxSize;
- CopyBits( &(GetOffscreenPtrFunction(theData)->portBits),
- &(GetWindowPtr(theData)->portBits),
- &tempRect, &tempRect, 0, 0L);
- }
-
- void ResizeControlsInMainWindow(WindowDataHandle theData)
- {
- TEHandle hTE;
-
- AdjustScrollSizes(GetWindowPtr(theData), hTE=GetTheTextHandle(), gVScrollBar, gHScrollBar);
- AdjustViewRect(hTE);
- TECalText(hTE);
- AdjustForEndScroll(gVScrollBar, hTE);
- gDestRect[kMainWindowTE]=(**hTE).destRect;
- gViewRect[kMainWindowTE]=(**hTE).viewRect;
- AdjustVScrollBar(gVScrollBar, hTE);
- }
-
- void DealWithEditMenu(WindowDataHandle theData, short theMessage)
- {
- Handle scrapHandle;
- long dummy;
- unsigned long scrapLength;
- TEHandle hTE;
-
- hTE=GetWindowData_hTE(theData, gWhichTE);
-
- switch (theMessage)
- {
- case kCut:
- TECut(hTE);
- ZeroScrap();
- TEToScrap();
- AdjustForEndScroll(gVScrollBar, hTE);
- break;
- case kCopy:
- TECopy(hTE);
- ZeroScrap();
- TEToScrap();
- break;
- case kPaste:
- scrapHandle=NewHandle(0L);
- if (GetScrap(scrapHandle, 'TEXT', &dummy)!=noTypeErr)
- {
- scrapLength=GetHandleSize(scrapHandle);
- TEFromScrap();
- TEPaste(hTE);
- }
- DisposeHandle(scrapHandle);
- break;
- case kClear:
- TEDelete(hTE);
- AdjustForEndScroll(gVScrollBar, hTE);
- break;
- case kSelectAll:
- TESetSelect(0, 32767, hTE);
- break;
- }
-
- TESelView(hTE);
- AdjustVScrollBar(gVScrollBar, hTE);
- }
-
- enum ErrorType ParserDispatch(WindowDataHandle theData)
- {
- enum ErrorType parseError;
- TEHandle rawTE;
-
- gCustomCursor=FALSE;
- gInProgress=TRUE;
- AdjustMenus();
- DrawMenuBar();
-
- rawTE=GetWindowData_hTE(theData, kMainWindowTE);
- InitTheParser(rawTE, 0, 32767);
- parseError=ParseLoop();
- if (parseError!=kNoError)
- {
- // put error reporting here
- }
-
- TESelView(rawTE);
- AdjustVScrollBar(gVScrollBar, rawTE);
-
- gInProgress=FALSE;
- AdjustMenus();
- DrawMenuBar();
-
- return parseError;
- }
-